#include "wyzkr688rfswinstance.h"
#include "Backend/wyzkr688rfswbackend.h"
#include "Hmi/wyzkr688rfswhmi.h"

WyZkR688RFSWInstance::WyZkR688RFSWInstance(short Local_Remote){
    if(Local_Remote == REMOTEHMI){
        this->pHmi = new wyzkr688rfswhmi(REMOTEHMI);
    }
    else if(Local_Remote == LOCALCONTOLLER) {
        this->pBackend = new wyzkr688rfswbackend();
        this->pHmi = new wyzkr688rfswhmi(LOCALCONTOLLER);
        this->RegisiterBackendtoHmi();
    }
}

WyZkR688RFSWInstance::~WyZkR688RFSWInstance(){
    if (this->pBackend != nullptr) delete this->pBackend;
    if (this->pHmi != nullptr) delete this->pHmi;
}

QWidget* WyZkR688RFSWInstance::getUiHandle(){
    if(this->pHmi != nullptr){
        return this->pHmi;
    }
    else{
        return nullptr;
    }
}

void WyZkR688RFSWInstance::RegisiterBackendtoHmi(){
    this->pHmi->getBackendhandle(this->pBackend);
}

short WyZkR688RFSWInstance::task_uifast_UiDataUpdate(){
    if(this->pHmi != nullptr){
        return this->pHmi->UiDataUpdate();
    }
    else{
        return UNDERTAKE;
    }
}

short WyZkR688RFSWInstance::task_uifast_ForceScopeUpdate(){
    if(this->pHmi != nullptr){
        return this->pHmi->ForceScopeUpdate();
    }
    else {
        return UNDERTAKE;
    }
}

short WyZkR688RFSWInstance::task_uifast_RobotScopeUpdate(){
    if(this->pHmi != nullptr){
        return this->pHmi->RobotScopeUpdate();
    }
    else {
        return UNDERTAKE;
    }
}

short WyZkR688RFSWInstance::task_maininit_toRobotTcpServerAdd(){
    if(this->pBackend != nullptr){
        return this->pBackend->toRobotTcpServerAdd();
    }
    else {
        return UNDERTAKE;
    }
}

short WyZkR688RFSWInstance::task_maininit_toRobotTcpServerListen(){
    if(this->pBackend != nullptr){
        return this->pBackend->toRobotTcpServerListen();
    }
    else {
        return UNDERTAKE;
    }
}

void WyZkR688RFSWInstance::task_mainloop_toRobotReceiveLoopRun(){
    if(this->pBackend != nullptr){
        this->pBackend->toRobotreceiveLoopRun();
    }
}

void  WyZkR688RFSWInstance::task_mainloop_toRobotSendLoopRun(){
    if(this->pBackend != nullptr){
        this->pBackend->toRobotsendLoopRun();
    }
}

void  WyZkR688RFSWInstance::task_mainloop_ProcessDataSave(){
    if(this->pBackend != nullptr){
        this->pBackend->ProcessDataSave();
    }
}

void WyZkR688RFSWInstance::task_com_RemoteDataRecv(QByteArray Data){
    if(this->pHmi != nullptr){
        this->pHmi->RemoteDataRecv(Data);
    }
}

void WyZkR688RFSWInstance::task_com_RemoteDataSend(QByteArray& Data){
    if(this->pHmi != nullptr){
        this->pHmi->RemoteDataSend(Data);
    }
    else{
    }
}

void WyZkR688RFSWInstance::task_mainloop_RfswProcessDeal(){
    if(this->pBackend != nullptr){
        this->pBackend->RFSWPorcess();
    }
}

